﻿Public Class frmListaPrecioLitado

    Private Sub frmComprasListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        fechaInicio.Value = DateTime.Now.AddDays(-30)
        fechaFin.Value = DateTime.Now
        dgCompras.AutoGenerateColumns = False
        Cargar_ListasPrecios()

    End Sub

    Dim controller As New ControllerSigeco.controller_stock()

    Private _codListaPrecio As Integer = 0

    Public Property codListaPrecio() As Integer
        Get
            Return _codListaPrecio
        End Get
        Set(ByVal value As Integer)
            _codListaPrecio = value
        End Set
    End Property

    Private m_frmListaPrecio As frmListaPrecio
    Public Property frmListaPrecios() As frmListaPrecio
        Get
            Return m_frmListaPrecio
        End Get
        Set(ByVal value As frmListaPrecio)
            m_frmListaPrecio = value
        End Set
    End Property

    Private Sub Cargar_ListasPrecios()

        Dim dt As New DataTable
        dt = controller.get_listas_precios(oiml.dbConn, fechaInicio.Value, fechaFin.Value, txtDescripcion.Text, cbxFin.Checked)
        dgCompras.DataSource = dt

    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click
        Try
            If dgCompras.SelectedRows.Count > 0 Then
                Dim cod As New Integer
                cod = dgCompras.SelectedRows(0).Cells(0).Value

                If frmListaPrecios Is Nothing Then

                    frmListaPrecios = New frmListaPrecio
                    frmListaPrecios.codListaPrecio = cod

                    'If frmClientes.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    frmListaPrecios.ShowDialog()
                    Cargar_ListasPrecios()
                    frmListaPrecios.Dispose()
                    frmListaPrecios = Nothing
                    'End If
                Else
                    frmListaPrecios.codListaPrecio = cod
                    frmListaPrecios.ShowDialog()
                End If

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        Cargar_ListasPrecios()
    End Sub

    Private Sub txtProveedor_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDescripcion.KeyDown
        If e.KeyCode = Keys.Enter Then
            Cargar_ListasPrecios()

        End If
    End Sub

    Private Sub dgCompras_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgCompras.DoubleClick
        btnEditar_Click(sender, e)
    End Sub

    Private Sub dgCompras_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgCompras.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click(sender, e)
        End If

    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        frmListaPrecios = New frmListaPrecio()
        frmListaPrecios.codListaPrecio = 0
        frmListaPrecios.ShowDialog()
        Cargar_ListasPrecios()
    End Sub

End Class